package TeacherEvaluation.com.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import TeacherEvaluation.com.entity.ClassInfo;
import TeacherEvaluation.com.entity.Department;
import TeacherEvaluation.com.entity.ResultMsg;
import TeacherEvaluation.com.service.classService;

/**
 * 班级管理所用控制器
 * @author azhao
 *2019/09/18
 */
@Controller
public class classController {
	@Autowired
	private classService classservice;
	
	
	// 添加班级页面
	@RequestMapping("/addClass")
	public ModelAndView classInfo() {
		List<Department> departments=classservice.selectDepartment();
		ModelAndView mv = new ModelAndView("admin/class/addClass");
		mv.addObject("departments",departments);
		return mv;
	}
	//新增班级
	@RequestMapping("/addClass_submit")
	@ResponseBody
	public ResultMsg addClass_submit(ClassInfo classInfo) {
		
		int i=classservice.getClassByClassName(classInfo.getClass_name());
		if(i>0) {
			return new ResultMsg(1, "此班级已存在!");
		}else{
			int classIn=classservice.insertClass(classInfo);
			if(classIn>0) {
				return new ResultMsg(0, "添加成功!");
			}else {
				return new ResultMsg(2, "添加失败!");
			}
			
		}
		
	}
	
	//访问查询班级页面
	@RequestMapping("/showClass")
	public ModelAndView showClass() {
		List<ClassInfo> classnum=classservice.selectClassNum();
		ModelAndView mv = new ModelAndView("admin/class/showClass");
		mv.addObject("classnum",classnum);
		return mv;
	}

}
